package com.cxxx.guns.modular.backend.controller;

import com.cxxx.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.cxxx.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.cxxx.guns.modular.backend.model.TeachersClass;
import com.cxxx.guns.modular.backend.service.ITeachersClassService;

/**
 * 师资信息控制器
 *
 * @author fengshuonan
 * @Date 2018-09-14 11:11:11
 */
@Controller
@RequestMapping("/teachersClass")
public class TeachersClassController extends BaseController {

    private String PREFIX = "/backend/teachersClass/";

    @Autowired
    private ITeachersClassService teachersClassService;

    /**
     * 跳转到师资信息首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "teachersClass.html";
    }

    /**
     * 跳转到添加师资信息
     */
    @RequestMapping("/teachersClass_add")
    public String teachersClassAdd() {
        return PREFIX + "teachersClass_add.html";
    }

    /**
     * 跳转到修改师资信息
     */
    @RequestMapping("/teachersClass_update/{teachersClassId}")
    public String teachersClassUpdate(@PathVariable Integer teachersClassId, Model model) {
        TeachersClass teachersClass = teachersClassService.selectById(teachersClassId);
        model.addAttribute("item",teachersClass);
        LogObjectHolder.me().set(teachersClass);
        return PREFIX + "teachersClass_edit.html";
    }

    /**
     * 获取师资信息列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return teachersClassService.selectList(null);
    }

    /**
     * 新增师资信息
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TeachersClass teachersClass) {
        teachersClassService.insert(teachersClass);
        return SUCCESS_TIP;
    }

    /**
     * 删除师资信息
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer teachersClassId) {
        teachersClassService.deleteById(teachersClassId);
        return SUCCESS_TIP;
    }

    /**
     * 修改师资信息
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TeachersClass teachersClass) {
        teachersClassService.updateById(teachersClass);
        return SUCCESS_TIP;
    }

    /**
     * 师资信息详情
     */
    @RequestMapping(value = "/detail/{teachersClassId}")
    @ResponseBody
    public Object detail(@PathVariable("teachersClassId") Integer teachersClassId) {
        return teachersClassService.selectById(teachersClassId);
    }
}
